﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Team4Mock.DAO
{
    public class TrustDistrictDAO
    {
        Helper h=new Helper();
        public void Insert(string name,string des,int regionid,int active)
        {
            SqlParameter[]p=new SqlParameter[4];
            p[0]=new SqlParameter("@name",name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@des", des);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@regionid", regionid);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@active", active);
            p[3].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("TrustDistrict_Insert",p);
        }
        public void Update(string name, string des, int active,int id)
        {
            SqlParameter[] p = new SqlParameter[4];
            p[0] = new SqlParameter("@name", name);
            p[0].SqlDbType = SqlDbType.NVarChar;
            p[1] = new SqlParameter("@des", des);
            p[1].SqlDbType = SqlDbType.NVarChar;
            p[2] = new SqlParameter("@active", active);
            p[2].SqlDbType = SqlDbType.Int;
            p[3] = new SqlParameter("@id", id);
            p[3].SqlDbType = SqlDbType.Int;
            h.ExecuteNonQuerry("TrustDistrict_Update", p);
        }
        //get by id regionid
        public DataTable Getdata(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("TrustDistrict_GetdataByID", p);
        }
        //get by id district
        public DataTable GetdataByDis(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetData("TrustDistrict_Getdata", p);
        }
        public string GetnameRegion(int id)
        {
            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@id", id);
            p[0].SqlDbType = SqlDbType.Int;
            return h.GetValueString("TrustDistrict_GetNamRegion", p);
        }
    }
}